package com.example.demo.thread.single_threaded_execution;

/**
 * Description: 以1个线程执行”的意思，有时也称为Critical Section（临界区）。<br/>
 *
 * @author liulonglong
 * @taskId <br/>
 * @Date 2019/11/20 14:39
 * @Version 1.0
 */
public class Gate {
    private int counter = 0;

    private String name = "Nobody";

    private String address = "Nowhere";

    public void pass(String name, String address) {
        this.counter++;
        this.name = name;
        this.address = address;
        check();
    }

    private void check() {
        if (name.charAt(0) != address.charAt(0)) {
            System.out.println("***** BROKEN ***** " + toString());
        }
    }

    public String toString() {
        return "No." + counter + ": " + name + ", " + address;
    }
}
